package com.itestor.iptv.modules.common.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.itestor.iptv.exceptions.ApplicationException;
import com.itestor.iptv.global.GlobalConstant;
import com.itestor.iptv.modules.common.CommonConstant;
import com.itestor.iptv.modules.common.bean.AlertConfigBean;
import com.itestor.iptv.modules.common.service.RobotConfigService;
import com.itestor.iptv.utils.SystemHelper;

/**
 * 
 * @author Mr.li
 * 
 */
public class RobotAlertCfgModifyAction extends Action {

    /**
     * Logger for this class.
     */
    private static final Logger logger = Logger
            .getLogger(RobotAlertCfgModifyAction.class);

    /**
     * 
     */
    public transient RobotConfigService robotConfigService;

    /**
     * @param mapping struts mapping
     * @param request request
     * @param form action form
     * @param response response
     * @return action forward
     * @throws Exception any exception
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String moveDelay = request.getParameter("moveDelay");
        String warnVol = request.getParameter("warnVol");
        String warnVolTimes = request.getParameter("warnVolTimes");
        String warnRtpLost = request.getParameter("warnRtpLost");
        String warnRtpSe = request.getParameter("warnRtpSe");
        String df = request.getParameter("df");
        String mlr = request.getParameter("mlr");
        String warnBitRatio = request.getParameter("warnBitRatio");
        String tcpRetran = request.getParameter("tcpRetran");
        String tcpOrderErr = request.getParameter("tcpOrderErr");
        
        AlertConfigBean bean = new AlertConfigBean();
        bean.setDf(df);
        bean.setMlr(mlr);
        bean.setWarnBitRatio(warnBitRatio);
        bean.setWarnRtpLost(warnRtpLost);
        bean.setWarnVolTimes(warnVolTimes);
        bean.setWarnVol(warnVol);
        bean.setMoveDelay(moveDelay);
        bean.setWarnRtpSe(warnRtpSe);
        bean.setTcpRetran(tcpRetran);
        bean.setTcpOrderErr(tcpOrderErr);
        
        try {
            robotConfigService.modifyAlertConfigBean(bean);
        } catch (Exception e) {
            throw new ApplicationException("robot.alert.config.error",
                    CommonConstant.PROPERTIES_BUNDLE);
        }

        SystemHelper.addMessage(request, "robot.alert.update.success",
                CommonConstant.PROPERTIES_BUNDLE);
        
        
        return mapping.findForward(GlobalConstant.FORWARD_SUCCESS);
    }

    /**
     * @param pRobotConfigService
     */
    public void setRobotConfigService(RobotConfigService pRobotConfigService) {
        robotConfigService = pRobotConfigService;
    }

}
